<?php

namespace app\api\model;

use app\common\model\BaseModel;
use app\common\library\common;
use think\facade\Db;

class Send extends BaseModel
{


    /**
     * 保洁人员派单信息
     * @param $wxapp_id
     * @param $data
     * @param $info
     * @return bool
     */
    public static function cleaning($data, $info)
    {
        $openid = $info['openid'];
        $appid = 'wxcf34f8be3e7a4461';
        $appkey = '85a7fee4834d3b9ef34cf9315f40919f';
        include_once "../app/common/library/wxpay/jssdk/jssdk.php";
        $jssdk = new \JSSDK($appid, $appkey);
        $url = $data['url'];
        $tempid = 'CX_1-TTgz5Sq_RUx3NMQmd6dqObc38hS9vn4mxtuSq8';
        $infos['character_string2']['value'] = urlencode($data['character_string2']['value']);
        $infos['thing10']['value'] = urlencode($data['thing10']['value']);
        $infos['thing11']['value'] = urlencode($data['thing11']['value']);

        $info = $jssdk->doSend($openid, $tempid, $url, $infos);
        return true;
    }

    /**
     * 保洁人员派单信息
     * @param $wxapp_id
     * @param $data
     * @param $info
     * @return bool
     */
    public static function sendaddorder($data, $info)
    {
        $openid = $info['openid'];
        $appid = 'wxcf34f8be3e7a4461';
        $appkey = '85a7fee4834d3b9ef34cf9315f40919f';
        include_once "../app/common/library/wxpay/jssdk/jssdk.php";
        $jssdk = new \JSSDK($appid, $appkey);
        $tempid = 'qOylyVZXnrrvO1dkTmbnujlyn2ueE8M5Hop0DWSi634';
        $url = $data['url'];
        $info['first']['value'] = urlencode($data['first']['value']);
        $info['first']['color'] = '#0000FF';
        $info['keyword1']['value'] = urlencode($data['keyword1']['value']);
        $info['keyword2']['value'] = urlencode($data['keyword2']['value']);
        $info['keyword3']['value'] = urlencode($data['keyword3']['value']);
        $info['keyword4']['value'] = urlencode($data['keyword4']['value']);
        $info['remark']['value'] = urlencode($data['keyword6']['value']);
        $info = $jssdk->doSend($openid, $tempid, $url, $info);
        return true;
    }


    /**
     * 订单通知
     * @param $data
     * @return bool
     */
    public static
    function send_order($order_on)
    {

        $list = Db::name('customer_order')->alias('o')
            ->field('o.order_on,o.seat_id,o.package_id,o.price,o.add_time,o.end_time,o.store_id,o.shi')
            ->join('customer_course c', 'o.seat_id=c.id')
            ->field('c.name as cname,c.id')
            ->join('customer_package p', 'o.package_id=p.id')
            ->field('p.name,p.id')
            ->where('o.mark', 1)->where('o.order_on', $order_on)
            ->find();
        $info = Db::name('customer_user')->where('room_id', $list['store_id'])->where('is_cleaning', 0)->where('mark', 1)->find();
        $send_message['url'] = '';
        $send_message['first']['value'] = '您好！您有新的预订单。';
        $send_message['keyword1']['value'] = $list['cname'];
        $send_message['keyword2']['value'] = $list['shi'].'小时';
        $send_message['keyword3']['value'] = $list['price'].'元';
        $send_message['keyword4']['value'] = date('Y-m-d h:i:s',$list['end_time']);
        $send_message['keyword6']['value'] = '感谢您的使用，更多信息请在系统后台查看';
        if($info['openid']!==null){
            return Send::sendaddorder($send_message, $info);
        }

    }
}